<template>
  <div>Child: {{ money }}</div>
  <button @click="handleClick">修改爷爷的 money</button>
</template>

<script>
import { inject } from 'vue'

export default {
  setup() {
    // #2 后代通过 inject 注入数据
    const money = inject('money')
    // #4 拿到方法
    const updateMoney = inject('updateMoney')
    const handleClick = () => {
      updateMoney(3)
    }
    return { money, handleClick }
  },
}
</script>

<style lang="scss" scoped></style>
